//
//  TVStatementHeaderView.swift
//  iPhone
//
//  Created by Toj on 11/15/22.
//

import UIKit

class TVStatementHeaderView: UIView {
    
    var headerViewModel: TVStatementHeaderViewModel? { didSet {
        dateLabel.text = headerViewModel?.date
        depositLabel.text = headerViewModel?.deposit
        spendingLabel.text = headerViewModel?.spending
    } }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupMakeAddSubviews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        setupMakeLayoutSubviews()
    }
    
    private lazy var dateLabel: UILabel = {
        let view = UILabel()
        view.font = 24.to_boldFont(name: .roboto)
        view.textColor = "#E8CD8C".to_color
        return view
    }()
    
    private lazy var depositTitleLabel: UILabel = {
        let view = UILabel()
        view.text = "Deposit: "
        view.font = 12.to_rbtRegularFont
        view.textColor = "#BBBBBB".to_color
        return view
    }()
    
    private lazy var depositLabel: UILabel = {
        let view = UILabel()
        view.font = 12.to_rbtBoldFont
        view.textColor = "#BBBBBB".to_color
        return view
    }()
   
    private lazy var spendingTitleLabel: UILabel = {
        let view = UILabel()
        view.text = "Spending: "
        view.font = 12.to_rbtRegularFont
        view.textColor = "#BBBBBB".to_color
        return view
    }()
    
    private lazy var spendingLabel: UILabel = {
        let view = UILabel()
        view.font = 12.to_rbtBoldFont
        view.textColor = "#BBBBBB".to_color
        return view
    }()
}

extension TVStatementHeaderView {
    
    private func setupMakeAddSubviews() {
       addSubview(dateLabel)
        addSubview(depositLabel)
        addSubview(depositTitleLabel)
        addSubview(spendingLabel)
        addSubview(spendingTitleLabel)
    }
    
    private func setupMakeLayoutSubviews() {
        
        dateLabel.snp.makeConstraints { make in
            make.centerY.equalTo(self)
            make.left.equalTo(20.ui_mscale)
        }
        
        depositLabel.snp.makeConstraints { make in
            make.right.equalTo(snp.right).offset(-20.ui_mscale)
            make.bottom.equalTo(snp.centerY).offset(-3)
        }
        
        depositTitleLabel.snp.makeConstraints { make in
            make.right.equalTo(depositLabel.snp.left)
            make.centerY.equalTo(depositLabel)
        }
        
        spendingLabel.snp.makeConstraints { make in
            make.right.equalTo(depositLabel)
            make.top.equalTo(snp.centerY).offset(3)
        }
        
        spendingTitleLabel.snp.makeConstraints { make in
            make.right.equalTo(spendingLabel.snp.left)
            make.centerY.equalTo(spendingLabel)
        }
    }
}
